package com.example.generics;

public class Demo2<T> {

    private T iterm;

    public Demo2() {

    }

    public Demo2(T iterm) {
        this.iterm = iterm;
    }

    public void setIterm(T iterm) {
        this.iterm = iterm;
    }

    public T getIterm() {
        return iterm;
    }
    public static void main(String[] args) {
        Demo2<String> stringDemo2 = new Demo2<>();
        stringDemo2.setIterm("hello");
        System.out.println(stringDemo2.getIterm());

        Demo2<Integer> integerDemo2 = new Demo2<>();
        integerDemo2.setIterm(123); // 这里有一个自动装箱的动作
        Integer i = integerDemo2.getIterm();
        System.out.println(i);

        Demo2 objectDemo2 = new Demo2();
        objectDemo2.setIterm(new Double(3.1415926));
        System.out.println(objectDemo2.getIterm());

        Demo2 objectDemo3 = new Demo2();
        objectDemo3.setIterm(3.1415926);
        System.out.println(objectDemo3.getIterm());
    }
}
